package com.leicx.guli.product.web;

import com.leicx.guli.common.exception.RRException;
import com.leicx.guli.product.service.SkuInfoService;
import com.leicx.guli.product.vo.sku.item.SkuItemVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;

/**
 * @author daxiong
 * @date 2022/7/25 下午1:48
 */
@Controller
public class ItemController {

    @Resource
    SkuInfoService skuInfoService;

    /**
     * 展示当前sku的详情
     *
     * @param skuId
     * @return java.lang.String
     * @author daxiong
     * @date 2022/7/25 下午1:52
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) {
        SkuItemVo skuItemVo = null;
        try {
            skuItemVo = skuInfoService.item(skuId);
        } catch (Exception e) {
            throw new RRException("查询详情出错：" + e.getMessage());
        }
        model.addAttribute("item", skuItemVo);
        return "item";
    }
}
